<script setup lang="ts">
import { watchCardAPI } from '@/apis/card';
import type { RechargeList, WatchCardType } from '@/types/card';
import { ref } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute()

// 获取月卡详情 ------------------------------
const watchCard = ref<WatchCardType>()
const getWatchCard = async (id: number) => {
    const res = await watchCardAPI(id)
    watchCard.value = res.data
}
if (route.params.id) {
    getWatchCard(Number(route.params.id))
}
// 支付方式
const paymentMethodFormatter = (row: RechargeList) => {
    if (row.paymentMethod === 'Alipay') {
        return '支付宝'
    } else if (row.paymentMethod === 'WeChat') {
        return '微信'
    } else {
        return '线下'
    }
}
// 日期
const formatDate = (row: RechargeList) => {
    return `${row.cardStartDate}至${row.cardEndDate}`
}
</script>

<template>
  <div class="add-card">
    <header class="add-header">
      <el-page-header content="查看详情" @back="$router.back()" />
    </header>
    <main class="add-main">
      <div class="form-container">
        <div class="title">车辆信息</div>
        <div class="carContent">
            <div class="tr">
                <div class="item">
                    <span class="label">车主姓名：</span>
                    <span class="value">{{ watchCard?.personName }}</span>
                </div>
                <div class="item">
                    <span class="label">车牌号码：</span>
                    <span class="value">{{ watchCard?.carNumber }}</span>
                </div>
            </div>
            <div class="tr">
                <div class="item">
                    <span class="label">联系方式：</span>
                    <span class="value">{{ watchCard?.phoneNumber }}</span>
                </div>
                <div class="item">
                    <span class="label">车辆品牌：</span>
                    <span class="value">{{ watchCard?.carBrand }}</span>
                </div>
            </div>
        </div>
      </div>
      <div class="form-container" style="margin-top: 20px; padding-bottom: 30px;">
        <div class="title">月卡缴费记录</div>
        <div class="cardContent" style="display: flex; justify-content: center;">
            <!-- 表格 序号 有效时间 支付金额 支付方式 办理时间 办理人 -->
            <el-table :data="watchCard?.rechargeList" style="width: 97%;">
                <el-table-column type="index" label="序号" width="180" />
                <el-table-column prop="" label="有效时间" width="280" :formatter="formatDate" />
                <el-table-column prop="paymentAmount" label="支付金额" />
                <el-table-column prop="paymentMethod" label="支付方式" :formatter="paymentMethodFormatter" />
                <el-table-column prop="createTime" label="办理时间" />
                <el-table-column prop="createUser" label="办理人" />
            </el-table>
        </div>
      </div>
    </main>
  </div>
</template>

<style scoped lang="scss">
.carContent {
    padding: 30px 0px 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .tr {
        width: 60%;
        display: flex;
        justify-content: space-between;
        flex-direction: column;
        margin-left: 180px;
        margin-bottom: 30px;
        .item {
            &:nth-child(1) {
                margin-bottom: 25px;
            }
        }
        .label {
            color: #9fa1a6;
            font-size: 14px;
        }
        .value {
            color: #393939;
            font-weight: 500;
            font-size: 15px;
        }
    }
}

.add-card {
  background-color: #f4f6f8;
  height: 100vh;

  .add-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;
    background-color: #fff;

    .left {
      span {
        margin-right: 4px;
      }

      .arrow {
        cursor: pointer;
      }
    }

    .right {
      text-align: right;
    }
  }

  .add-main {
    background: #f4f6f8;
    padding: 20px 130px;

    .form-container {
      background-color: #fff;

      .title {
        height: 60px;
        line-height: 60px;
        padding-left: 20px;
        border-bottom: 1px solid #ebeef5;
      }

      .form {
        margin-bottom: 20px;
        padding: 20px 65px 24px;

        .el-form {
          display: flex;
          flex-wrap: wrap;

          .el-form-item {
            width: 50%;
          }
        }
      }
    }

    .preview {
      img {
        width: 100px;
      }
    }
  }

  .add-footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 24px 50px;
    color: #000000d9;
    font-size: 14px;
    background: #fff;
    text-align: center;
  }
}
</style>